Skip to content

Fixed the yes/no prompt in verdi computer delete#6624

Merged
agoscinski merged 3 commits intoaiidateam:mainfrom
Krishnabhujade:fix/yes/no-prompt-verdi-computer-delete
May 6, 2025
Merged

Fixed the yes/no prompt in verdi computer delete#6624
agoscinski merged 3 commits intoaiidateam:mainfrom
Krishnabhujade:fix/yes/no-prompt-verdi-computer-delete

Conversation

@Krishnabhujade
Copy link
Copy Markdown
Contributor

This PR fixes the "yes/no" prompt in verdi computer delete

Fixes #6422

@agoscinski
Copy link
Copy Markdown
Collaborator

I am sorry for the back and forth but reading now the conversation in issue #6422 more carefully and looking at the deletion in other parts of the code. We can change it to [y/N], this gives us consistency over the CLI which I think is nice. We use click.confirm in other parts of the code for this.

Comment thread src/aiida/cmdline/commands/cmd_computer.py Outdated
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from ce1ff59 to ccc2832 Compare November 25, 2024 12:37
Comment thread src/aiida/cmdline/commands/cmd_computer.py Outdated
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from 1225c23 to 1f5aea4 Compare November 25, 2024 15:42
@Krishnabhujade
Copy link
Copy Markdown
Contributor Author

I am sorry for the back and forth but reading now the conversation in issue #6422 more carefully and looking at the deletion in other parts of the code. We can change it to [y/N], this gives us consistency over the CLI which I think is nice. We use click.confirm in other parts of the code for this.

Ohk @agoscinski I will do '[y/N]'

@Krishnabhujade
Copy link
Copy Markdown
Contributor Author

@agoscinski
I am facing some problem in setting up the codebase locally

@agoscinski
Copy link
Copy Markdown
Collaborator

No worries I take over. It should now work.

@Krishnabhujade
Copy link
Copy Markdown
Contributor Author

I want to contribute more to organisation so I want to install the codebase locally

@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch 2 times, most recently from e3f8bef to a33cfb2 Compare November 26, 2024 09:33
@agoscinski
Copy link
Copy Markdown
Collaborator

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 26, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.59%. Comparing base (474e0fa) to head (183465f).
⚠️ Report is 53 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6624      +/-   ##
==========================================
+ Coverage   78.58%   78.59%   +0.01%     
==========================================
  Files         567      567              
  Lines       43086    43087       +1     
==========================================
+ Hits        33856    33861       +5     
+ Misses       9230     9226       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@agoscinski agoscinski requested a review from khsrali November 26, 2024 14:40
@Krishnabhujade
Copy link
Copy Markdown
Contributor Author

Thank you sir

Copy link
Copy Markdown
Collaborator

@khsrali khsrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @Krishnabhujade and @agoscinski ,
Some minor comments

Comment thread tests/cmdline/commands/test_computer.py Outdated
def test_computer_delete_nonexisting_computer(self):
"""Test if `verdi computer delete` command works correctly for a nonexisting computer"""
# See if the command complains about not getting an nonexisting computer
self.cli_runner(computer_delete, ['computer_that_does_not_exist'], raises=True)
Copy link
Copy Markdown
Collaborator

@khsrali khsrali Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check explicitly if the raise is due to NotExistent.
Also please pass user_input=y I know here it might not matter because the query comes before click.confirm,
however, later if someone changes the order of the logic in the code then test might silently pass..
Better to be precise.
Thanks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot check the actual exception at the CLI level, we only get a system exit. I added assert for the error message that relate to that exception.

Comment thread src/aiida/cmdline/commands/cmd_computer.py
Comment thread tests/cmdline/commands/test_computer.py Outdated
orm.Computer.collection.get(label=label)
# Safety check in case of --dry-run
options = [label, '--dry-run']
self.cli_runner(computer_delete, options)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cli_runner(computer_delete, options)
self.cli_runner(computer_delete, options, user_input="y")

Comment thread tests/cmdline/commands/test_computer.py Outdated
# Setup a computer to delete during the test
label = 'computer_for_test_label'
orm.Computer(
def test_computer_delete_existing_computer(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this test name kinda misleading for it's purpose

Suggested change
def test_computer_delete_existing_computer(self):
def test_computer_do_not_delete(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

named it test_computer_delete_existing_computer_not_deleted do be consistent with the test name of the other one

@agoscinski agoscinski self-assigned this Feb 19, 2025
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch 2 times, most recently from 85d7c21 to 6c69993 Compare March 6, 2025 07:30
@agoscinski agoscinski requested a review from khsrali March 6, 2025 08:51
Copy link
Copy Markdown
Collaborator

@khsrali khsrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @agoscinski, all good!

@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from 6c69993 to e14a2bc Compare March 25, 2025 09:12
@agoscinski agoscinski moved this to Done in aiida-core v2.7.0 Mar 25, 2025
orm.load_code(c_label)

def test_computer_delete(self):
"""Test if 'verdi computer delete' command works"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this test is deleted.
Where do we actually check if the the command would function, when deleting a computer that has no associated nodes?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true the diff looks weird now. I just redo this PR when I have time

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this test exists I restructured the tests a bit, made them more granular. I restructured the tests test_computer_delete and test_computer_delete_with_nodes to more granular test cases test_computer_delete_existing_computer_successful, test_computer_delete_existing_computer_not_deleted and test_computer_delete_nonexisting_computer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok still I don't see a test that would delete a computer without associated nodes.

Like this:

  def test_computer_delete_no_associated nodes(self):
    orm.Computer(..).store().configure()
    self.cli_runner(computer_delete, [label])
    with pytest.raises(NotExistent):
      orm.Computer.collection.get(label=label)
       

@agoscinski agoscinski moved this from Done to In progress in aiida-core v2.7.0 May 5, 2025
@agoscinski agoscinski moved this to In review in aiida-core v2.7.1 May 5, 2025
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from a674a64 to 35f14e3 Compare May 6, 2025 05:51
@agoscinski agoscinski requested a review from khsrali May 6, 2025 05:52
@agoscinski agoscinski moved this to In review in aiida-core v2.7.0 May 6, 2025
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch 2 times, most recently from a48331c to 030627a Compare May 6, 2025 07:03
Copy link
Copy Markdown
Collaborator

@khsrali khsrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alex we need a test like this to make sure not having associated nodes will not prompt for an input and can function as before:

  def test_computer_delete_no_associated nodes(self):
    orm.Computer(..).store().configure()
    self.cli_runner(computer_delete, [label])
    with pytest.raises(NotExistent):
      orm.Computer.collection.get(label=label)
       

# Ensures that 'yes' works for backwards compatibility, see issue #6422
@pytest.mark.parametrize('user_input', ['y', 'yes'])
def test_computer_delete_existing_computer_successful(self, user_input):
"""Test if `verdi computer delete` successfully deletes when applied on an existing computer."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Test if `verdi computer delete` successfully deletes when applied on an existing computer."""
"""Test if `verdi computer delete` successfully deletes when applied on an existing computer, which has associated nodes."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no difference if you delete a node that is associated to something

$ node delete 8
Report: 1 Node(s) marked for deletion
Warning: YOU ARE ABOUT TO DELETE 1 NODES! THIS CANNOT BE UNDONE!

Comment thread tests/cmdline/commands/test_computer.py Outdated
Comment thread tests/cmdline/commands/test_computer.py Outdated
Comment thread tests/cmdline/commands/test_computer.py Outdated
orm.load_code(c_label)

def test_computer_delete(self):
"""Test if 'verdi computer delete' command works"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok still I don't see a test that would delete a computer without associated nodes.

Like this:

  def test_computer_delete_no_associated nodes(self):
    orm.Computer(..).store().configure()
    self.cli_runner(computer_delete, [label])
    with pytest.raises(NotExistent):
      orm.Computer.collection.get(label=label)
       

Copy link
Copy Markdown
Collaborator

@khsrali khsrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch 2 times, most recently from 048a9f0 to 699f27f Compare May 6, 2025 12:23
Krishnabhujade and others added 3 commits May 6, 2025 16:44
The yes/no prompt of `verdi computer delete` is the only prompt in the
CLI that does not accept 'y' as valid answer but only 'yes'. This has
been aligned with the other prompts to also support 'y'.

Restructure the tests `test_computer_delete` and
`test_computer_delete_with_nodes` to more granular test cases
`test_computer_delete_existing_computer_successful`,
`test_computer_delete_existing_computer_not_deleted` and
`test_computer_delete_nonexisting_computer`

Cleanup names in tests.
The mock timeout is reached in CI so we increase it.
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from 699f27f to 183465f Compare May 6, 2025 14:44
@khsrali
Copy link
Copy Markdown
Collaborator

khsrali commented May 6, 2025

What's happening here after my approval 👀

@agoscinski agoscinski merged commit 71fc14f into aiidateam:main May 6, 2025
11 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in aiida-core v2.7.0 May 6, 2025
@agoscinski
Copy link
Copy Markdown
Collaborator

Everything is fine here, please Sir review my next PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

More user friendly yes/no prompt in verdi computer delete

3 participants